package com.shuimin.as.util;

import io.netty.util.CharsetUtil;
import pond.common.FILE;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

/**
 * Created by sky on 2015/8/13.
 */
public class ErrorMessageUtil {

    public static Map<Integer, String> errors = new HashMap<>();

    public static void init(String fileName) {
        errors.clear();
        Properties p = FILE.loadProperties(fileName);
        Iterator keys = p.keySet().iterator();
        while (keys.hasNext()) {
            String _key = (String) keys.next();

            String _o = (String) p.get(_key);
            Integer key = Integer.parseInt(_key);
            try {
                String val = new String(_o.getBytes(CharsetUtil.ISO_8859_1), "UTF-8");
                errors.put(key, val);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

        }
    }

    public static String get(int code) {
        return errors.get(code) == null ? "" : errors.get(code);
    }
}
